/**
 * 对layui的一些操作进行封装,封装Tips
 * @author lijun
 */
var Tips = {
	//信息框
	success : function(message){
		layer.msg(message,{icon : 1});
	},
	error : function(message){
		layer.msg(message,{icon : 2});
	},
	warn : function(message){
		layer.msg(message,{icon : 7});
	},
	info : function(message){
		layer.msg(message);
	},
	//加载层
	load : function(){
		layer.load();
	}
};

/**
 * 对异步请求进行封装，包括异步分页。
 * @author lijun
 */
var webParam = {
	page_limit: 10,
	page_curr: 1,
	page_count: 10
};
var Load = {
	ajax : function(type,url,params,async,callback){
		layer.load();
		$.ajax({
			type: type,
			url: url,
			data: params,
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			async: async,
			timeout: '5000',
			dataType: 'json',
			success: callback,
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				if(textStatus == 'timeout') { //超时,status还有success,error等值的情况
					layer.msg("请求超时：请检查网络连接", {time: 2000});
				} else {
					layer.msg(textStatus + ":" + XMLHttpRequest.responseText, {time: 2000});
				}
			},
			complete: function() {
				layer.closeAll('loading');
			}
		});
	},
	pageAjax : function(type,url,params,async,callback){
		layer.load();
		$.ajax({
			type: type,
			url: url,
			data: params,
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			async: async,
			timeout: '5000',
			dataType: 'json',
			success: callback,
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				if(textStatus == 'timeout') { //超时,status还有success,error等值的情况
					layer.msg("请求超时：请检查网络连接", {time: 2000});
				} else {
					layer.msg(textStatus + ":" + XMLHttpRequest.responseText, {time: 2000});
				}
			},
			complete: function() {
				layer.closeAll('loading');
				//执行一个laypage实例
				laypage.render({
					elem: 'pageBar',
					count: webParam.page_count,
					limit: webParam.page_limit,
					curr: webParam.page_curr,
					prev: "<span class='page-op'><i class='ali-font icon-left_icon'></i></span>上一页",
					next: "下一页<span class='page-op'><i class='ali-font icon-right_icon'></i></span>",
					layout: ['prev', 'page', 'next'],
					jump: function(obj, first) {
						if(!first) {
							webParam.page_curr = obj.curr;
							webParam.loadData();	//需要定义
						}
					}
				});
			}
		});
	}
};